<?php

namespace app\admin\controller;
use app\common\controller\Adminbase;
use think\Controller;
use think\Db;
use think\Request;
use think\Session;

import('Curl', EXTEND_PATH);
import('Interfaces', EXTEND_PATH);
/**
 * 跑马灯/公告控制器
 */
//class system extends AdminBase {
 class system extends controller {

	 /**
     * 跑马灯/公告
     * @return
     */
    public function Notice(){
        $this->assign('verify_type', config('verify_type'));
        return $this->fetch('Notice');
    }
     /**
     * 历史记录 跑马灯/公告
     * @return
     */
    public function Notice_1(){
        $this->assign('verify_type', config('verify_type'));
        return $this->fetch('Notice_1');
    }
    /**
     * 添加跑马灯
     * @return
     */
    public function horse_add(){
        $content = input("param.content");//内容
        $starTime = input("param.start_time");//开始时间
        $endTime = input("param.end_time");//结束时间
        $interval_time = input("param.speed");//时间间隔
        $speed = SPEED;//速度
        $data = date("Y-m-d H:i:s",time());
        if($starTime > $data){
            $status = 2;
        }else{
            $status = 1;
        }
        $data = [
            'appid'=>APP_ID,
            'content'=>$content,
            'start_time'=>$starTime,
            'end_time'=>$endTime,
            'interval_time'=>$interval_time,
            'speed'=>$speed,
            'status'=>$status
        ];
        $data = json_encode($data);
        $url =HTTP."api/horse_add.php";
        $curl = new \Curl();
        $result = $curl->vpost($url,$data);
   		// print_r($url);

        return $result;
        
    }
    /**
     * 修改跑马灯
     * @return
     */
    public function horse_update(){
        $id = input("param.id");//主键id
        $content = input("param.content");//内容
        $starTime = input("param.start_time");//开始时间
        $endTime = input("param.end_time");//结束时间
        $interval_time = input("param.speed");//时间间隔
        $speed = SPEED;//速度
        $data = [
            'appid'=>APP_ID,
            'id'=>$id,
            'content'=>$content,
            'start_time'=>$starTime,
            'end_time'=>$endTime,
            'speed'=>$speed,
            'interval_time'=>$interval_time,
        ];
        $data = json_encode($data);
        $url =HTTP."api/horse_update.php";
        $curl = new \Curl();
        $result = $curl->vpost($url,$data);

        return $result;
        
    }
    /**
     * 修改跑马灯状态
     * @return
     */
    public function update_horse_status(){
        $id = input("param.id");//主键id
        $status = input("param.status");//状态
        $data = [
            'appid'=>APP_ID,
            'id'=>$id,
            'status'=>$status,
        ];
        $data = json_encode($data);
        $url =HTTP."api/update_horse_status.php";
        $curl = new \Curl();
        $result = $curl->vpost($url,$data);

        return $result;
        
    }
    /**
     * 筛选跑马灯列表
     * @return
     */
    public function horse_list_search(){
        $startDate = input("param.start_time");//开始时间
        $endDate = input("param.end_time");//结束时间
        $status = input("param.status");
        $data = [
            'appid'=>APP_ID,
        ];
        if($startDate !=""&& $endDate !=""){
            $data['startDate'] =$startDate;
            $data['endDate'] =$endDate;
        }
        if($status !=""){
            $data['status'] =$status;
        }
        $data = json_encode($data);
        $url =HTTP."api/horse_list_search.php";
        $curl = new \Curl();
        $result = $curl->vpost($url,$data);
        $obj = json_decode($result);

        return json($obj->data);
        
    }
     /**
     * 获取跑马灯参数列表
     * @return
     */
    public function horse_list(){
        $limit = 20;//截取条数
        $data = [
            'appid'=>APP_ID,
            'limit'=>$limit
        ];
        $data = json_encode($data);
        $url =HTTP."api/horse_list.php";
        $curl = new \Curl();
        $result = $curl->vpost($url,$data);
        $obj = json_decode($result);

        return json($obj->data);
        
    }
    /**
     * 删除跑马灯
     * @return
     */
    public function horse_del(){
        $id = input("param.id");//主键id
        $data = [
            'appid'=>APP_ID,
            'id'=>$id,

        ];
        $data = json_encode($data);
        $url =HTTP."api/horse_del.php";
        $curl = new \Curl();
        $result = $curl->vpost($url,$data);

        return $result;
        
    }

    /**
     * 添加公告
     * @return
     */
    public function notice_add(){
        $title = input("param.title");//标题
        $content = input("param.content");//内容
        $starTime = input("param.start_time");//开始时间
        $endTime = input("param.end_time");//结束时间
        $sort = input("param.sort");//排序
        $data = date("Y-m-d H:i:s",time());
        if($starTime > $data){
            $status = 2;
        }else{
            $status = 1;
        }
        $data = [
            'appid'=>APP_ID,
            'title' =>$title,
            'content'=>$content,
            'start_time'=>$starTime,
            'end_time'=>$endTime,
            'sort'=>$sort,
            'status'=>$status
        ];
        $data = json_encode($data);
        $url =HTTP."api/notice_add.php";
        $curl = new \Curl();
        $result = $curl->vpost($url,$data);

        return $result;
        
    }
    /**
     * 修改公告
     * @return
     */
    public function notice_update(){
        $id = input("param.id");//主键id
        $title = input("param.title");//标题
        $content = input("param.content");//内容
        $starTime = input("param.start_time");//开始时间
        $endTime = input("param.end_time");//结束时间
        $sort = input("param.sort");//排序
        $data = [
            'appid'=>APP_ID,
            'id'=>$id,
            'title' =>$title,
            'content'=>$content,
            'start_time'=>$starTime,
            'end_time'=>$endTime,
            'sort'=>$sort,
        ];
        $data = json_encode($data);
        $url =HTTP."api/notice_update.php";
        $curl = new \Curl();
        $result = $curl->vpost($url,$data);

        return $result;
        
    } /**
     * 筛选公告灯列表
     * @return
     */
    public function notice_list_search(){
        $startDate = input("param.start_time");//开始时间
        $endDate = input("param.end_time");//结束时间
        $status = input("param.status");
        $data = [
            'appid'=>APP_ID,
        ];
        if($startDate !=""&& $endDate !=""){
            $data['startDate'] =$startDate;
            $data['endDate'] =$endDate;
        }
        if($status !=""){
            $data['status'] =$status;
        }
        $data = json_encode($data);
        $url =HTTP."api/notice_list_search.php";
        $curl = new \Curl();
        $result = $curl->vpost($url,$data);
        $obj = json_decode($result);

        return json($obj->data);
        
    }
    /**
     * 获取公告参数列表
     * @return
     */
    public function notice_list(){
        $limit = 20;//截取条数
        $data = [
            'appid'=>APP_ID,
            'limit'=>$limit
        ];
        $data = json_encode($data);
        $url =HTTP."api/notice_list.php";
        $curl = new \Curl();
        $result = $curl->vpost($url,$data);
        $obj = json_decode($result);
        return json($obj->data);
        
    }
    /**
     * 修改公告状态
     * @return
     */
    public function update_notice_status(){
        $id = input("param.id");//主键id
        $status = input("param.status");//状态
        $data = [
            'appid'=>APP_ID,
            'id'=>$id,
            'status'=>$status,
        ];
        $data = json_encode($data);
        $url =HTTP."api/update_notice_status.php";
        $curl = new \Curl();
        $result = $curl->vpost($url,$data);

        return $result;
        
    }
    /**
     * 删除公告
     * @return
     */
    public function notice_del(){
        $id = input("param.id");//主键id
        $data = [
            'appid'=>APP_ID,
            'id'=>$id,

        ];
        $data = json_encode($data);
        $url =HTTP."api/notice_del.php";
        $curl = new \Curl();
        $result = $curl->vpost($url,$data);

        return $result;
        
    }

}